package cn.jilian.entity;

import java.util.Date;
import java.util.Map;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ConstraintMode;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.MapKeyClass;
import javax.persistence.MapKeyColumn;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Where;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name="bt_role",uniqueConstraints=@UniqueConstraint(columnNames = {"text", "unid" }))
@DynamicInsert
@DynamicUpdate
public class Role extends AbstractEntity{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 3009131068372738144L;

	public static final int RANK=100044000;
	
	public static final int METAID=138641;
	
	public Role() {
		this.setRank(RANK);
		this.setFlag(1);
	}
	
	private String name;
	
	private String text;
	
	private Long unid;
	
	@ElementCollection(fetch=FetchType.EAGER)
	@MapKeyColumn(name="fid")
	@MapKeyClass(Long.class)
	@Column(name="act")
	@CollectionTable(
			name = "bt_mace",
			joinColumns = @JoinColumn(name = "uid",foreignKey =@ForeignKey(name = "none",value = ConstraintMode.NO_CONSTRAINT))
		)
	@Where(clause="rank="+Mace.MENU_MACE_RANK)
	private Map<Long,Integer> menuMaceMap;

	private Integer flag;
	
	private Date tims;
	
	

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Long getUnid() {
		return unid;
	}

	public void setUnid(Long unid) {
		this.unid = unid;
	}

	@JsonIgnore
	public Map<Long, Integer> getMenuMaceMap() {
		return menuMaceMap;
	}

	public void setMenuMaceMap(Map<Long, Integer> menuMaceMap) {
		this.menuMaceMap = menuMaceMap;
	}

	public Integer getFlag() {
		return flag;
	}

	public void setFlag(Integer flag) {
		this.flag = flag;
	}

	public Date getTims() {
		return tims;
	}

	public void setTims(Date tims) {
		this.tims = tims;
	}
	
}
